package model.diagram.providers;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import model.ModelPackage;
import model.diagram.edit.parts.ActorEditPart;
import model.diagram.edit.parts.ActorPackActorEditPart;
import model.diagram.edit.parts.ActorsPackageEditPart;
import model.diagram.edit.parts.AssociationActorToSerieEditPart;
import model.diagram.edit.parts.EpisodeEditPart;
import model.diagram.edit.parts.EpisodesPackEpisodeEditPart;
import model.diagram.edit.parts.EpisodesPackageEditPart;
import model.diagram.edit.parts.RoleEditPart;
import model.diagram.edit.parts.SeasonEditPart;
import model.diagram.edit.parts.SeasonPackageEditPart;
import model.diagram.edit.parts.SeasonsPackSeasonEditPart;
import model.diagram.edit.parts.SerieEditPart;
import model.diagram.edit.parts.SerieRoleEditPart;
import model.diagram.edit.parts.SeriesPackSerieEditPart;
import model.diagram.edit.parts.SeriesPackageEditPart;
import model.diagram.edit.parts.WorkspaceEditPart;
import model.diagram.part.ModelDiagramEditorPlugin;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

/**
 * @generated
 */
public class ModelElementTypes {

	/**
	 * @generated
	 */
	private ModelElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map<IElementType, ENamedElement> elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set<IElementType> KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType Workspace_1000 = getElementType("org.ProjectWithoutName.diagram.Workspace_1000"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ActorsPackage_2001 = getElementType("org.ProjectWithoutName.diagram.ActorsPackage_2001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType SeriesPackage_2002 = getElementType("org.ProjectWithoutName.diagram.SeriesPackage_2002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType SeasonPackage_2015 = getElementType("org.ProjectWithoutName.diagram.SeasonPackage_2015"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType EpisodesPackage_2016 = getElementType("org.ProjectWithoutName.diagram.EpisodesPackage_2016"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Actor_2010 = getElementType("org.ProjectWithoutName.diagram.Actor_2010"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Serie_2011 = getElementType("org.ProjectWithoutName.diagram.Serie_2011"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Season_2012 = getElementType("org.ProjectWithoutName.diagram.Season_2012"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Episode_2008 = getElementType("org.ProjectWithoutName.diagram.Episode_2008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Role_2009 = getElementType("org.ProjectWithoutName.diagram.Role_2009"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType SeriesPackSerie_4001 = getElementType("org.ProjectWithoutName.diagram.SeriesPackSerie_4001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ActorPackActor_4002 = getElementType("org.ProjectWithoutName.diagram.ActorPackActor_4002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType SeasonsPackSeason_4003 = getElementType("org.ProjectWithoutName.diagram.SeasonsPackSeason_4003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType EpisodesPackEpisode_4004 = getElementType("org.ProjectWithoutName.diagram.EpisodesPackEpisode_4004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType SerieRole_4005 = getElementType("org.ProjectWithoutName.diagram.SerieRole_4005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType AssociationActorToSerie_4006 = getElementType("org.ProjectWithoutName.diagram.AssociationActorToSerie_4006"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return ModelDiagramEditorPlugin.getInstance()
						.getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap<IElementType, ENamedElement>();

			elements.put(Workspace_1000, ModelPackage.eINSTANCE.getWorkspace());

			elements.put(ActorsPackage_2001,
					ModelPackage.eINSTANCE.getActorsPackage());

			elements.put(SeriesPackage_2002,
					ModelPackage.eINSTANCE.getSeriesPackage());

			elements.put(SeasonPackage_2015,
					ModelPackage.eINSTANCE.getSeasonPackage());

			elements.put(EpisodesPackage_2016,
					ModelPackage.eINSTANCE.getEpisodesPackage());

			elements.put(Actor_2010, ModelPackage.eINSTANCE.getActor());

			elements.put(Serie_2011, ModelPackage.eINSTANCE.getSerie());

			elements.put(Season_2012, ModelPackage.eINSTANCE.getSeason());

			elements.put(Episode_2008, ModelPackage.eINSTANCE.getEpisode());

			elements.put(Role_2009, ModelPackage.eINSTANCE.getRole());

			elements.put(SeriesPackSerie_4001,
					ModelPackage.eINSTANCE.getSeriesPackSerie());

			elements.put(ActorPackActor_4002,
					ModelPackage.eINSTANCE.getActorPackActor());

			elements.put(SeasonsPackSeason_4003,
					ModelPackage.eINSTANCE.getSeasonsPackSeason());

			elements.put(EpisodesPackEpisode_4004,
					ModelPackage.eINSTANCE.getEpisodesPackEpisode());

			elements.put(SerieRole_4005, ModelPackage.eINSTANCE.getSerieRole());

			elements.put(AssociationActorToSerie_4006,
					ModelPackage.eINSTANCE.getAssociationActorToSerie());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet<IElementType>();
			KNOWN_ELEMENT_TYPES.add(Workspace_1000);
			KNOWN_ELEMENT_TYPES.add(ActorsPackage_2001);
			KNOWN_ELEMENT_TYPES.add(SeriesPackage_2002);
			KNOWN_ELEMENT_TYPES.add(SeasonPackage_2015);
			KNOWN_ELEMENT_TYPES.add(EpisodesPackage_2016);
			KNOWN_ELEMENT_TYPES.add(Actor_2010);
			KNOWN_ELEMENT_TYPES.add(Serie_2011);
			KNOWN_ELEMENT_TYPES.add(Season_2012);
			KNOWN_ELEMENT_TYPES.add(Episode_2008);
			KNOWN_ELEMENT_TYPES.add(Role_2009);
			KNOWN_ELEMENT_TYPES.add(SeriesPackSerie_4001);
			KNOWN_ELEMENT_TYPES.add(ActorPackActor_4002);
			KNOWN_ELEMENT_TYPES.add(SeasonsPackSeason_4003);
			KNOWN_ELEMENT_TYPES.add(EpisodesPackEpisode_4004);
			KNOWN_ELEMENT_TYPES.add(SerieRole_4005);
			KNOWN_ELEMENT_TYPES.add(AssociationActorToSerie_4006);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

	/**
	 * @generated
	 */
	public static IElementType getElementType(int visualID) {
		switch (visualID) {
		case WorkspaceEditPart.VISUAL_ID:
			return Workspace_1000;
		case ActorsPackageEditPart.VISUAL_ID:
			return ActorsPackage_2001;
		case SeriesPackageEditPart.VISUAL_ID:
			return SeriesPackage_2002;
		case SeasonPackageEditPart.VISUAL_ID:
			return SeasonPackage_2015;
		case EpisodesPackageEditPart.VISUAL_ID:
			return EpisodesPackage_2016;
		case ActorEditPart.VISUAL_ID:
			return Actor_2010;
		case SerieEditPart.VISUAL_ID:
			return Serie_2011;
		case SeasonEditPart.VISUAL_ID:
			return Season_2012;
		case EpisodeEditPart.VISUAL_ID:
			return Episode_2008;
		case RoleEditPart.VISUAL_ID:
			return Role_2009;
		case SeriesPackSerieEditPart.VISUAL_ID:
			return SeriesPackSerie_4001;
		case ActorPackActorEditPart.VISUAL_ID:
			return ActorPackActor_4002;
		case SeasonsPackSeasonEditPart.VISUAL_ID:
			return SeasonsPackSeason_4003;
		case EpisodesPackEpisodeEditPart.VISUAL_ID:
			return EpisodesPackEpisode_4004;
		case SerieRoleEditPart.VISUAL_ID:
			return SerieRole_4005;
		case AssociationActorToSerieEditPart.VISUAL_ID:
			return AssociationActorToSerie_4006;
		}
		return null;
	}

}
